//
//  AXFUserDetailController.m
//  BeeQuick
//
//  Created by 王誉升 on 2016/11/19.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "AXFUserDetailController.h"
#import "AXFUserDetailCell.h"
#import "AXFUserDetailModel.h"
#import "AXFUserCell.h"

static NSString *userDetailCell = @"userDetailCell";
static NSString *userCell = @"userCell";
@interface AXFUserDetailController ()

@end

@implementation AXFUserDetailController
{
    NSArray <AXFUserDetailModel *> *_userDetailList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
    
    self.navigationItem.title = @"使用规则";
    
    //自定义导航条返回按钮
    UIBarButtonItem *leftBButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(clickToMyVC:)];
    
    self.navigationItem.leftBarButtonItem = leftBButton;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"AXFUserDetailCell" bundle:nil] forCellReuseIdentifier:userDetailCell];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"AXFUserCell" bundle:nil] forCellReuseIdentifier:userCell];
    
    self.tableView.rowHeight = 130;
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)clickToMyVC:(UIBarButtonItem *)batBtn
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)loadData
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"userDetail.plist" withExtension:nil];
    
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        AXFUserDetailModel *model = [AXFUserDetailModel modelWithDict:obj];
        
        [arrayM addObject:model];
        
    }];
    
    _userDetailList = arrayM.copy;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _userDetailList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == _userDetailList.count - 1)
    {
        AXFUserCell *cell = [tableView dequeueReusableCellWithIdentifier:userCell forIndexPath:indexPath];
        
        cell.model = _userDetailList[indexPath.row];
        
        return cell;
    }
    
    AXFUserDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:userDetailCell forIndexPath:indexPath];
    
    cell.model = _userDetailList[indexPath.row];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
